package com.fh.controller.system.parameter;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fh.controller.base.BaseController;
import com.fh.model.system.User;
import com.fh.service.system.organization.OrganizationServiceImpl;
import com.fh.util.Const;
import com.fh.util.DateUtil;
import com.fh.util.IpUtil;
import com.fh.util.ResultJSON;

@Controller
@RequestMapping("parameter")
public class ParameterController extends BaseController{
	private Logger loger = LoggerFactory.getLogger(ParameterController.class);
	
	@Autowired
	private OrganizationServiceImpl service;
	
	@RequestMapping("list")
	public String index(){
		
		return "system/parameter/list";
	}
	
	/**
	 * 修改分组时间
	 * 
	 * @return
	 */
	@RequestMapping("update")
	@ResponseBody
	public ResultJSON updateOrganization(Integer S1Max,Integer S2Min,Integer S2Max,Integer S3){
		ResultJSON json = new ResultJSON();
		HttpServletRequest request = this.getRequest();
		String ip = IpUtil.getIpAddress(request);
		//shiro管理的session
		Subject currentUser = SecurityUtils.getSubject();  
		Session session = currentUser.getSession();
		User user = (User)session.getAttribute(Const.SESSION_USER);
		try {
			service.updateByOrganization(S1Max,S2Min,S2Max,S3);
			//更新成功后在日志中打印出ip在在什么时候修改过
			loger.info("分组被修改了,修改的ip是==>{}", ip + " " + DateUtil.getTime() + " " + user.getUSERNAME());
			json.setMsg("更新成功!");
		} catch (Exception e) { 
			json.setSuccess(false);
			json.setMsg(e.getMessage());
		}
		return json;
	}
}
